﻿<UserControl x:Class="SterlingExample.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ViewModel="clr-namespace:SterlingExample.ViewModel" xmlns:Converter="clr-namespace:SterlingExample.Converter" xmlns:Views="clr-namespace:SterlingExample.Views" xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="800">
    <UserControl.Resources>
        <Converter:FoodGroupCountConverter x:Key="FoodGroupCount"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.DataContext>
            <ViewModel:MainViewModel/>
        </Grid.DataContext>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid Margin="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="20"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <Button Content=" REBUILD DATABASE " HorizontalAlignment="Center" Command="{Binding RebuildDatabase}"/>
                <TextBlock FontWeight="Bold" VerticalAlignment="Center" Margin="10 0 0 0" Text="Select Food Group:"/>
                <Button Content=" Clear Selection " Margin="10 0 0 0" HorizontalAlignment="Center" Command="{Binding ClearGroup}"/>
            </StackPanel>
            <ListBox Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" 
                     SelectedItem="{Binding CurrentGroup,Mode=TwoWay}"
                     ItemsSource="{Binding FoodGroups}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding GroupName}" ToolTipService.ToolTip="{Binding Converter={StaticResource FoodGroupCount}}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>            
        </Grid>
        <Grid Margin="5" Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>               
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock FontWeight="Bold" Text="Search Food: " VerticalAlignment="Center"/>
            <TextBox 
                VerticalAlignment="Center"
                Grid.Column="1" Margin="1" Text="{Binding SearchText,Mode=TwoWay}" TextChanged="TextBox_TextChanged"/>
            <ListBox Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" 
                     VerticalAlignment="Top" 
                     SelectedItem="{Binding CurrentFoodItem,Mode=TWoWay}"
                     ItemsSource="{Binding SearchResults}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Description}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
        <Views:FoodDescription Grid.Column="2"/>
    </Grid>
</UserControl>
